import numpy as np

class DataGenerator:
    def __init__(self, rows, cols):
        self.rows = rows
        self.cols = cols

    def generate_data(self):
        # 生成随机数据
        data = np.random.rand(self.rows, self.cols)
        # 添加一列随机数
        random_column = np.random.rand(self.rows, 1)
        return np.hstack((data, random_column))

    def write_data_to_file(self, filename):
        data = self.generate_data()
        # 将数据写入文件
        with open(filename, 'w') as f:
            for row in data:
                f.write(','.join(map(str, row)) + '\n')

    def read_data_from_file(self, filename):
        with open(filename, 'r') as f:
            for line in f:
                print(line.strip())